package com.notepad.util;

import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.notepad.ui.LockActivity;

import java.util.TimerTask;

/**
 * Created by jiamengyu on 1/19/2015.
 */
public class LockTask extends TimerTask {
    private final static String TAG = "LockTask";
    private Context mContext;
    private ActivityManager mActivityManager;
    private String currentPackgeName = "com.notepad";
    //private String currentClassName = "com.notepad.ui.MainActivity";

    public LockTask(Context context) {
        mContext = context;
        mActivityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
    }

    @Override
    public void run() {
        ComponentName topActivity = mActivityManager.getRunningTasks(1).get(0).topActivity;
        String packgeName = topActivity.getPackageName();
        String className = topActivity.getClassName();
        Log.d(TAG,"packgeName="+packgeName);
        Log.d(TAG,"className="+className);

        if(currentPackgeName.equals(packgeName) /*&& currentClassName.equals(className)*/){
            Intent intent = new Intent();
            intent.setClass(mContext, LockActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(intent);
        }
    }

}
